package com.bawei.weizichao_gao6.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bawei.weizichao_gao6.R;
import com.bawei.weizichao_gao6.model.bean.HealthBean;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Time: 2021/7/15
 * Author:weizichao
 * Description:Weizichao_Gao6
 */
public class HomeHealthAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {



    private Context context;
    private List<HealthBean.ResultEntity> list;

    public HomeHealthAdapter(Context context, List<HealthBean.ResultEntity> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getItemViewType(int position) {
        String s = list.get(position).thumbnail;
        String[] split = s.split(";");
        if (split.length == 1) {
            return 0;
        } else {
            return 1;
        }

    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if (viewType == 0) {
            return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.health_item2, parent, false));
        } else if (viewType == 1) {
            return new ViewHolder2(LayoutInflater.from(context).inflate(R.layout.health_item, parent, false));
        }
        return null;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {


        if (holder instanceof ViewHolder) {
            ((ViewHolder) holder).simpleHealth2.setImageURI(list.get(position).thumbnail);
            ((ViewHolder) holder).itemHealth2.setText(list.get(position).title);
            ((ViewHolder) holder).sourceHealth2.setText(list.get(position).source);
            ((ViewHolder) holder).releaseTimeHealth2.setText(list.get(position).releaseTime+"");
        } else if (holder instanceof ViewHolder2) {
            ((ViewHolder2) holder).itemHealth3.setText(list.get(position).title);
            String s = list.get(position).thumbnail;
            String[] split = s.split(";");
            ((ViewHolder2) holder).simpleHealth31.setImageURI(split[0]);
            ((ViewHolder2) holder).simpleHealth32.setImageURI(split[1]);
            ((ViewHolder2) holder).simpleHealth33.setImageURI(split[2]);
            ((ViewHolder2) holder).sourceHealth3.setText(list.get(position).source);
            ((ViewHolder2) holder).releaseTimeHealth3.setText(list.get(position).releaseTime+"");
        }

    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.simple_health_2)
        SimpleDraweeView simpleHealth2;
        @BindView(R.id.item_health_2)
        TextView itemHealth2;
        @BindView(R.id.source_health_2)
        TextView sourceHealth2;
        @BindView(R.id.releaseTime_health_2)
        TextView releaseTimeHealth2;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    class ViewHolder2 extends RecyclerView.ViewHolder {

        @BindView(R.id.item_health_3)
        TextView itemHealth3;
        @BindView(R.id.simple_health_3_1)
        SimpleDraweeView simpleHealth31;
        @BindView(R.id.simple_health_3_2)
        SimpleDraweeView simpleHealth32;
        @BindView(R.id.simple_health_3_3)
        SimpleDraweeView simpleHealth33;
        @BindView(R.id.source_health_3)
        TextView sourceHealth3;
        @BindView(R.id.releaseTime_health_3)
        TextView releaseTimeHealth3;

        public ViewHolder2(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
